﻿using UnityEngine;
using System.Collections;
using System.IO;

public class Database
{
	public static StreamWriter stream_writer;
	public static StreamReader stream_reader;

	public static string file_name  = "Save_Game.txt";
	public static string[] team_names;
	public static string[,] teams;
	public static string[] player_names;

	void Start ()
	{
	
	}

	void Update ()
	{
	
	}

	public static void Create_Profile()
	{
		if (File.Exists(file_name)) 
		{
			stream_writer.WriteLine("#" + Player.name.ToString() + ";");
			stream_writer.WriteLine("$" + Player.money.ToString() + ";");
			stream_writer.WriteLine("@" + Player.olimpcoins.ToString() + ";");
			stream_writer.WriteLine("");
			stream_writer.Close();
		}
		else
		{
			stream_writer = File.CreateText(file_name);
			stream_writer.WriteLine("#" + Player.name.ToString() + ";");
			stream_writer.WriteLine("$" + Player.money.ToString() + ";");
			stream_writer.WriteLine("@" + Player.olimpcoins.ToString() + ";");
			stream_writer.WriteLine("");
			stream_writer.Close();
		}
	}

	public static void Save_Database()
	{
		
	}

	public static void Load_Database()
	{
		stream_reader = new StreamReader(file_name);
		string[] database = stream_reader.ReadToEnd().Replace("\n", "").Split(';');
		for (int i = 0; i < database.Length; i++)
		{
			if (database[i].StartsWith("*T: "))
			{
				team_names = database[i].Replace("*T: ", "").Split(',');
			}

			if (database[i].StartsWith("*P: "))
			{
				player_names = database[i].Replace("*P: ", "").Split('!');
			}

			//Debug.Log(team_names[i]);
			Debug.Log(player_names[i]);
		}

		stream_reader.Close();

	}


}